package com.sgb.kjwl.view.ui.activity.home;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import androidx.databinding.DataBindingUtil;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityHomeCategoryBinding;
import com.sgb.kjwl.view.ui.fragment.CategoryFragment4;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.di.AppComponent;

/**
 * @author Administrator
 */
public class HomeCategoryActivity extends AppActivity {
    public static final int CATEGORY = 0;
    private ActivityHomeCategoryBinding binding;
    private FragmentManager fragmentManager;
    private Fragment myFragment[] = new Fragment[1];
    private boolean isStartAct = true;

    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, HomeCategoryActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }

    public static void start(Context context,boolean isStartAct) {
        Intent intent = new Intent();
        intent.setClass(context, HomeCategoryActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra("isActivity",isStartAct);
        context.startActivity(intent);
    }

    public static void start(Activity activity, int requestCode) {
        Intent intent = new Intent();
        intent.setClass(activity,HomeCategoryActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        activity.startActivityForResult(intent,requestCode);
    }

    @Override
    protected boolean statusBarDark() {
        return false;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        isStartAct = getIntent().getBooleanExtra("isActivity",true);
        initFragment(savedInstanceState);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(HomeCategoryActivity.this, R.layout.activity_home_category);
        binding.setViewModel(new BaseViewModel());
    }

    private void initFragment(Bundle savedInstanceState) {
        if (savedInstanceState == null) {
            fragmentManager = getSupportFragmentManager();
            if (isStartAct){
                myFragment[CATEGORY] = CategoryFragment4.newInstance(true,2);
            }else {
                myFragment[CATEGORY] = CategoryFragment4.newInstance(false,2);
            }
            fragmentManager.beginTransaction().add(R.id.content, myFragment[CATEGORY]).commit();
        }
    }

    @SuppressLint("MissingSuperCall")
    @Override
    protected void onSaveInstanceState(Bundle outState) {

    }
}